#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>


 char*const argv[]={
    "ls",
    "-a",
    "-l",
    NULL
};

const char* myenv[]={
    "MY_VALUE+123456",
    "ABCD=999999999",
    NULL
};

int main()
{
    putenv("WWWWWWWWWWW=00000000000000000000000");
    pid_t id=fork();
    if(id==0)
    {
        printf("hello world!\n");
        //execl("/usr/bin/ls","ls","-a","-l",NULL);
        //execlp("ls","ls","-a","-l",NULL);
        //execv("/usr/bin/ls",argv);
        //execvp("ls",argv);
        
        //使用exec系列函数调用我们自己的命令
        //execl("./outCode","./outCode",NULL);
        //execl("/usr/bin/bash","bash","test.sh",NULL);
        //execle("./outCode","./outCode",NULL,myenv);
        execl("./outCode","./outCode",NULL);
        exit(-1);
    }
    else if(id>0)
    {
        pid_t rid=waitpid(id,NULL,0);
        if(rid==id)
        {
            printf("wait %d success\n",id);
        }
        else if(rid==0)
        {
            printf("子进程还未结束\n");
        }
        else
        {
            perror("wait fail\n");
        }
    }

    //printf("begin replace:\n");
    //execl("/usr/bin/ls","ls","-a","-l",NULL);

    //printf("end replace:\n");
    return 0;
}


